/*
4.12
time:20201118 23:55 PM
key:1.无论是查看最小还是最大都是遍历，检查也是遍历检查，没有用到动态规划。
user：ldc
*/

#include <iostream>
using namespace std;

class Node
{
public:
	int data;
	Node* next;
	Node()
	{
		data = 0;
		next = NULL;
	}
};
//参数: 矩阵，行数，列数，目标行i1
int find_i_min(int** mat, int m, int n, int i1)
{
	int min=999999;
	int  j;
	for (j = 0; j < n; j++)
	{
		if (min > mat[i1][j])
		{
			min = mat[i1][j];
		}
	}
	//遍历完第i行的每个元素就退出
	return min;
}
//参数: 矩阵，行数，列数，目标列j1
int find_j_max(int** mat, int m, int n, int j1)
{
	int max = -999999;
	int i;

	for (i = 0; i < m; i++)
	{
		if (max < mat[i][j1])
		{
			max = mat[i][j1];
		}
	}
	//遍历完第j列的每个元素就退出
	return max;
}

int main()
{

	int** mat = new int*;
	int i,m,j,n;
	//输入矩阵的行与列 如 2 2
	cout << "分别输入矩阵行与列"<<endl;
	cin >> m>>n;
	//建立矩阵的行与列 
	for (i = 0; i < m; i++)
	{
		mat[i] = new int[n];
	}
	//输入矩阵的行与列 如 3 4 2 1
	cout<<"由行及列地输入"<<endl;
	for (i = 0; i < m; i++)
	{
		for (j= 0;j < n; j++)
		{
			//mat[i][j] = i+j;
			cin >> mat[i][j];
		}
	}
	//输出矩阵的行与列
	cout << "矩阵显示如下" << endl;
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			cout<<mat[i][j];
		}
		cout << "\n";
	}
	/*
	//输出矩阵第i行的最小值
	cout<<find_i_min(mat, m, n, 0)<<endl;
	//输出矩阵第j列的最小值
	cout<<find_j_max(mat, m, n, 0) << endl;
	*/
	//由行及列地遍历，查看是否每个元素都同时满足 find_i_min 和 find_j_max的条件，若满足则输出。
	cout << "开始输出鞍点" << endl;
	int a, b;
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			a = find_i_min(mat, m, n, i);
			b = find_j_max(mat, m, n, i);
			if ((mat[i][j] == a) && (mat[i][j] == b))
			{
				cout << i << "行" << j << "列" << "值为" << a << "是鞍点" << endl;
			}
		}
		
	}


}




